<?php
/**
 * The loop that displays a single post.
 *
 * The loop displays the posts and the post content.  See
 * http://codex.wordpress.org/The_Loop to understand it and
 * http://codex.wordpress.org/Template_Tags to understand
 * the tags used in it.
 *
 * This can be overridden in child themes with loop-single.php.
 *
 * @package WordPress
 * @subpackage Twenty_Ten
 * @since Twenty Ten 1.2
 */
//the_title(); 
// the_ID();
//the_content(); 
?>

<?php if ( have_posts() ) while ( have_posts() ) : the_post(); ?>
<?php
function the_post_thumbnail_caption() {
  $thumbnail_id    = get_post_thumbnail_id($post->ID);
  $thumbnail_image = get_posts(array('p' => $thumbnail_id, 'post_type' => 'attachment'));

  if ($thumbnail_image && isset($thumbnail_image[0])) {
    echo '<em>'.$thumbnail_image[0]->post_excerpt.'</em>';
  }
}

?>
<div class="news-page clearfix reseter">
    <div class="title clearfix reseter">
    <h2><?php echo the_title(); ?></h2>
        <div class="tools">от <a href="<?php echo esc_url(get_author_posts_url(get_the_author_meta( 'ID' ))) ?>"><?php echo get_the_author_meta('display_name'); ?></a> в <?php the_time('g:i'); ?> <span><?php the_time('d/m/Y'); ?></span>
            <script type="text/javascript" src="//yandex.st/share/share.js" charset="utf-8"></script>
            <span class="yashare-auto-init"
                 data-yashareL10n="ru"
                 data-yashareType="none"
                 data-yashareQuickServices="yaru,vkontakte,facebook,twitter,odnoklassniki,moimir,lj,friendfeed,moikrug">
            </span> 
        </div>
      </div>
      <div class="post-img">
      <?php
        if ( has_post_thumbnail() ) {
                the_post_thumbnail(array(340, 255));
                the_post_thumbnail_caption();
        }
      ?>
      </div>
      <div class="sub-title">
        <?php echo $post->post_excerpt; ?>
      </div>
      <?php echo $post->post_content; ?>
</div><!--news-page-->

<div class="news-tools clearfix reseter">
    <a href="/" style="color: grey;" class="link_tag">Проследить всю цепочку событий по этой теме</a>

    <div class="social">
        <span style='float:right; margin-top: -7px;'>
            <script type="text/javascript" src="//yandex.st/share/share.js" charset="utf-8"></script>
            <span class="yashare-auto-init"
                 data-yashareL10n="ru"
                 data-yashareType="none"
                 data-yashareQuickServices="yaru,vkontakte,facebook,twitter,odnoklassniki,moimir,lj,friendfeed,moikrug">
            </span>
        </span>
        <a href="javascript:window.print();" ><img src="<?php echo get_template_directory_uri() ?>/assets/images/ico_print.png" alt="" /></a>
    </div>
    <a href="/obratnaya-svyaz/" class="link_error">Сообщить об ошибке</a>
    <a href="javascript:scroll(0,0);" class="link_totop">Наверх</a>
</div>
<div class="news-author clearfix reseter">
    <div id="author-avatar" class='avatar'>
        <?php echo get_avatar( get_the_author_meta( 'user_email' ), apply_filters( 'twentyten_author_bio_avatar_size', 60 ) ); ?>
    </div><!-- #author-avatar -->
    <div class="news-author-name">
        Автор: <a href="<?php echo esc_url(get_author_posts_url(get_the_author_meta( 'ID' ))) ?>"><?php the_author(); ?></a>
    </div>
    <p><?php echo get_the_author_meta( 'description' ); ?></p>
</div>
<?php
    $post_categories = wp_get_post_categories($post->ID);
    $data = array();
    foreach($post_categories as $cat){
        if($cat != 1){
            $arg = array('numberposts' => 3,
                         'category' => $cat);
            $data = array_merge($data, get_posts($arg));
        }
    }
    if(count($data) == 0)
        $data = get_posts(array('numberposts' => 3, 'category' => 1));
    else {
        shuffle($data);
        array_splice($data, 3);
    }
?>
<div class="title" style="font-size: 11px;
                          line-height: 22px;
                          text-transform: uppercase;">Ссылки по теме</div>
<div class="news_list">
<?php foreach ($data as $item) {?>
    <div class="item clearfix" style='min-height:0px;
                                      margin-bottom: 5px;
                                      padding-bottom: 3px;
                                      background: none;
                                      border-bottom: 1px solid #d8d5c4;
                                      font-size: 11px;'>
          <a href="<?php echo get_permalink($item->ID); ?>"
           title="<?php echo htmlspecialchars($item->post_title); ?>"><?php echo $item->post_title ?></a><br>
        <?php echo $item->post_excerpt?>&nbsp;&nbsp;<a href="<?php echo get_permalink($item->ID); ?>">Дальше &rarr;</a>
         <div class="tools">
            <span class="date">
                <span><?php echo date("H:i ",strtotime($item->post_date)); ?></span>
                <?php echo date("d/m",strtotime($item->post_date)); ?>
            </span>
        </div>
    </div>
<?php } ?>
</div>
<!--div class="related_cols clearfix">
    <?php dynamic_sidebar('related-cols-widget-area'); ?>
</div-->
<!--center>
<script type="text/javascript">
google_ad_client = "ca-pub-2489976528038386";
/* горизонтальный */
google_ad_slot = "3440992329";
google_ad_width = 728;
google_ad_height = 90;

</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
</center-->
<br />
<?php comments_template( '', true ); ?>

<?php endwhile; // end of the loop. ?>
